package su.msk.jet.team01.chatik.server.commands;

import su.msk.jet.team01.chatik.server.data.Client;
import su.msk.jet.team01.chatik.server.exception.InvalidArgumentException;

public abstract class Command {

	protected static final int MAX_MESSAGE_LENGTH = 1000;

	private String name;
	private int argsCount;

	protected Command(final String name, final int argsCount) {
		this.name = name;
		this.argsCount = argsCount;
	}

	public String getName() {
		return name;
	}

	public int getArgsCount() {
		return argsCount;
	}

	public abstract void execute(Client client, String[] args)
			throws InvalidArgumentException;

	protected void validateHaveNoSpaces(final String input)
			throws InvalidArgumentException {
		if (input.matches(".*\\s.*")) {
			throw new InvalidArgumentException(
					"Invalid argument format: contain spaces.");
		}
	}

	protected void validateLength(final String str, final int maxLength)
			throws InvalidArgumentException {
		if (str.length() > maxLength) {
			throw new InvalidArgumentException("Argument too long: received " + str.length() + ", maximum " + maxLength);
		}
	}
}
